﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SR_MessageDemo
{
    public partial class FormList : Form
    {

        public FormList()
        {
            InitializeComponent();
        }


        private void FormList_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            BindingList<User> list = new BindingList<User>
            {
                new User{Name="小燕子",Age=20,Gender="女"},
                new User{Name="五阿哥",Age=22,Gender="男"},
                new User{Name="尔康",Age=24,Gender="男"},
                new User{Name="刘青",Age=27,Gender="男"},
                new User{Name="刘红",Age=24,Gender="女"},
                new User{Name="程序员Ken",Age=29,Gender="男",Role="管理员"},
            };
            this.dataGridView1.DataSource = list;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            BindingList<User> lists = this.dataGridView1.DataSource as BindingList<User>;
            User user = lists[e.RowIndex];
            FormEdit formEdit = new FormEdit(user);
            formEdit.StartPosition = FormStartPosition.CenterParent;
            formEdit.ShowDialog(this);
        }

       
    }
}
